package com.pan.admin.module.channel.service.impl;

import com.gitee.apanlh.util.valid.ValidParam;
import com.pan.admin.common.utils.DateUtils;
import com.pan.admin.common.utils.SecurityUtils;
import com.pan.admin.module.channel.dao.LoanChannelDao;
import com.pan.admin.module.channel.dao.LoanChannelMarketDao;
import com.pan.admin.module.channel.entity.LoanChannelMarket;
import com.pan.admin.module.channel.service.LoanChannelMarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 渠道关联产品Service业务层处理
 *
 * @author ts
 * @date 2023-09-18
 */
@Service
public class LoanChannelMarketServiceImpl implements LoanChannelMarketService {

    @Autowired
    private LoanChannelDao loanChannelDao;
    @Autowired
    private LoanChannelMarketDao loanChannelMarketDao;

    /**
     * 根据ID获取列表渠道关联产品
     *
     * @param id 渠道关联产品主键
     * @return 渠道关联产品
     */
    @Override
    public LoanChannelMarket getById(Long id) {
        return loanChannelMarketDao.getById(id);
    }

    /**
     * 查询渠道关联产品列表
     *
     * @param loanChannelMarket 渠道关联产品
     * @return 渠道关联产品
     */
    @Override
    public List<LoanChannelMarket> list(LoanChannelMarket loanChannelMarket) {
        return loanChannelMarketDao.list(loanChannelMarket);
    }

    /**
     * 新增渠道关联产品
     *
     * @param loanChannelMarket 渠道关联产品
     * @return 结果
     */
    @Override
    public int insertLoanChannelMarket(LoanChannelMarket loanChannelMarket) {
        loanChannelMarket.setCreateTime(DateUtils.getNowDate());
        loanChannelMarket.setCreateBy(SecurityUtils.getUsername());
        return loanChannelMarketDao.insertLoanChannelMarket(loanChannelMarket);
    }

    /**
     * 修改渠道关联产品
     *
     * @param loanChannelMarket 渠道关联产品
     * @return 结果
     */
    @Override
    public int updateLoanChannelMarket(LoanChannelMarket loanChannelMarket) {
        loanChannelMarket.setUpdateTime(DateUtils.getNowDate());
        loanChannelMarket.setUpdateBy(SecurityUtils.getUsername());
        Integer enableTop = loanChannelMarket.getEnableTop();

        if (ValidParam.isNotNull(enableTop)) {
            if (enableTop == 1) {
                loanChannelMarketDao.updateEnableTop();
            }
        }
        return loanChannelMarketDao.updateLoanChannelMarket(loanChannelMarket);
    }

    /**
     * 批量删除渠道关联产品
     *
     * @param ids 需要删除的渠道关联产品主键
     * @return 结果
     */
    @Override
    public int batchDeleteById(Long[] ids) {
        return loanChannelMarketDao.batchDeleteById(ids);
    }

    /**
     * 删除渠道关联产品信息
     *
     * @param id 渠道关联产品主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id) {
        return loanChannelMarketDao.deleteById(id);
    }
}
